<template>
  <el-form
    :model="form"
    label-width="180px"
    v-loading="isLoading"
  >
    <el-form-item label="部门最大人数">
      <el-input-number
        style="width:300px"
        v-model="form.maxUserMembershipCount"
        :min="1"
        :precision="0"
        :step="1"
      />
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        @click="submit"
      >
        保存
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { getDepartmentRule, setDepartmentRule } from '@/http/rule'
import { ElMessage } from 'element-plus'

const form = ref({
  maxUserMembershipCount: 0
})
const isLoading = ref(false)

onMounted(() => {
  getData()
})

const getData = async () => {
  isLoading.value = true
  const res = await getDepartmentRule()
  form.value = res
  isLoading.value = false
}

const submit = async () => {
  isLoading.value = true
  await setDepartmentRule(form.value)
  isLoading.value = false
  ElMessage.success('保存成功')
}
</script>

<style scoped lang="scss">

</style>
